<template>
  <div>
    <el-table :data="withdraws" highlight-current-row stripe v-loading="loading" element-loading-text="拼命加载中"
      element-loading-spinner="el-icon-loading" element-loading-background="#fafafa" style="width: 100%; margin-top: 10px;">
      <el-table-column type="index" label="编号" align="center" width="60">
      </el-table-column>
      <el-table-column prop="uid" label="uid" align="center" width="120">
      </el-table-column>
      <el-table-column prop="applyUser" label="申请人" align="center" width="100">
      </el-table-column>
      <el-table-column prop="nickName" label="昵称" align="center" width="120">
      </el-table-column>
      <el-table-column prop="zfb" label="支付宝" align="center" width="120">
      </el-table-column>
      <el-table-column prop="applyTime" label="申请时间" align="center" width="180">
      </el-table-column>
      <el-table-column prop="finish_time" label="完成时间" align="center" width="180">
      </el-table-column>
      <el-table-column label="备注" align="center" width="120">
        <template slot-scope="scope">
          <el-popover placement="bottom" width="200" trigger="hover"
                      :content="scope.row.remark?scope.row.remark:remark">
            <el-tag slot="reference">查看</el-tag>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column prop="statusDesc" label="状态" align="center" width="80">
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="success" @click="showGiro(scope.row)">转账通知</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination @current-change="handleCurrentChange" :current-page="queryParam.page" @size-change="handleSizeChange"
                   :page-size="queryParam.size" layout="total, sizes, prev, pager, next, jumper" background
                   :total="count">
    </el-pagination>

    <el-dialog title="转账通知" :visible.sync="dialogVisible" width="40%" :before-close="handleClose">
      <el-form :model="currentUser" label-width="100px" class="form">
        <el-form-item label="申请人">
          <el-input v-model="currentUser.applyUser" placeholder="用户uid" type="text" disabled></el-input>
        </el-form-item>
        <el-form-item label="提现结果">
          <el-select v-model="currentUser.status" placeholder="请选择提现结果">
            <el-option v-for="item in status" :key="item.code" :label="item.msg" :value="item.code">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="currentUser.remark" placeholder="提现失败必填" type="text"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" round @click="submitForm()">保存</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  getUserWithdrawList,
  giro,
  getDic
} from '@/apis/XcxApi'

export default {
  name: 'Withdraw',
  data () {
    return {
      currentUser: {},
      dialogVisible: false,
      withdraws: [],
      count: 0,
      queryParam: {
        page: 1,
        size: 10,
        uid: null,
        status: null
      },
      remark: '暂无',
      status: [],
      loading: false
    }
  },
  created () {
    this.getUserWithdrawList()
    this.getDic()
  },
  methods: {
    getUserWithdrawList () {
      this.loading = true
      getUserWithdrawList(this.queryParam).then(res => {
        if (res.data) {
          this.withdraws = res.data.getUserWithdraws
          this.count = res.data.count
        }
        this.loading = false
      })
    },
    showGiro (user) {
      this.currentUser = user
      this.dialogVisible = true
    },
    getDic () {
      getDic({
        type: 'userWithdrawStatus'
      }).then(res => {
        this.status = res.data
      })
    },
    giro () {
      giro(this.currentUser).then(res => {
        if (res.data) {
          this.$message.success('消息发送成功')
          this.dialogVisible = false
          this.getUserWithdrawList()
        } else {
          this.$message.error('消息发送失败')
        }
      })
    },
    // 每页显示的数量改变时
    handleSizeChange (val) {
      this.queryParam.size = val
      this.getUserWithdrawList()
    },
    // 当前页码改变时
    handleCurrentChange (val) {
      this.queryParam.page = val
      this.getUserWithdrawList()
    },
    // 关闭对话框
    handleClose (done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done()
        })
        .catch(_ => {
        })
    },
    // 提交表单 修改用户信息
    submitForm () {
      this.giro()
    }
  }
}
</script>

<style scoped>
.form {
  width: 65%;
}

.el-pagination {
  margin-top: 10px;
}
</style>
